# demo02_subprocess.py
import subprocess
# 执行系统命令
# subprocess.run('ls')
# subprocess.run('ls /opt')  # 报错，不支持参数
# subprocess.run(['ls', '/opt'])
# subprocess.run(['echo', '$HOME'])
# 告诉python解释器，执行的就是一个shell命令
# subprocess.run('echo $HOME', shell=True)
# subprocess.run('ls /opt', shell=True)

# 查看执行结果是否成功
# result = subprocess.run('ls /abc &> /dev/null', shell=True)
result = subprocess.run('systemctl start mariadb', shell=True)
# print(result)
print('返回码：', result.returncode)
if result.returncode == 0:
    print('执行成功')
else:
    print('执行失败')





